package com.cole.gx095.controller.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class CommonRep {
    private Integer code;
    private Map<String,Object> data = new HashMap<>();
    private boolean success;
    private String message;

    private CommonRep(){}

    public static CommonRep ok(){
        CommonRep CommonRep = new CommonRep();
        CommonRep.setSuccess(true);
        CommonRep.setCode(20000);
        CommonRep.setMessage("成功");
        return CommonRep;
    }
    public static CommonRep warn(String message){
        CommonRep CommonRep = new CommonRep();
        CommonRep.setSuccess(false);
        CommonRep.setCode(20000);
        CommonRep.setMessage(message);
        return CommonRep;
    }

    public static CommonRep error(){
        CommonRep CommonRep = new CommonRep();
        CommonRep.setSuccess(false);
        CommonRep.setCode(10000);
        CommonRep.setMessage("失败");
        return CommonRep;
    }

    public CommonRep success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public CommonRep message(String message){
        this.setMessage(message);
        return this;
    }

    public CommonRep code(Integer code){
        this.setCode(code);
        return this;
    }

    public CommonRep data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public CommonRep data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
}
